; RUN: clspv-opt -constant-args-ubo %s -o %t.ll --passes=multi-version-ubo-functions,remove-unused-arguments
; RUN: FileCheck %s < %t.ll

; CHECK: define {{.*}} @k1
; CHECK-DAG: [[ex0:%[a-zA-Z0-9_.]+]] = extractelement <4 x i32> {{.*}}, i64 0
; CHECK-DAG: [[ex1:%[a-zA-Z0-9_.]+]] = extractelement <4 x i32> {{.*}}, i64 1
; CHECK: call {{.*}} [[bar:@bar[a-zA-Z0-9_.]+]](i32 [[ex0]], i32 [[ex1]])
; CHECK: define {{.*}} [[bar]](i32 [[v0:%[a-zA-Z0-9_.]+]], i32 [[v1:%[a-zA-Z0-9_.]+]])
; CHECK: [[res:%[a-zA-Z0-9_.]+]] = call ptr addrspace(2) @_Z14clspv.resource.1
; CHECK: [[gep:%[a-zA-Z0-9_.]+]] = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) [[res]], i32 0, i32 0, i32 [[v0]]
; CHECK: [[res:%[a-zA-Z0-9_.]+]] = call ptr addrspace(2) @_Z14clspv.resource.1
; CHECK: [[gep:%[a-zA-Z0-9_.]+]] = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) [[res]], i32 0, i32 0, i32 [[v1]]

target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir-unknown-unknown"

@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer

define dso_local spir_func <4 x i32> @bar(ptr addrspace(2) nocapture readonly %in1, ptr addrspace(2) nocapture readonly %in2) {
entry:
  %0 = load <4 x i32>, ptr addrspace(2) %in1, align 16
  %1 = load <4 x i32>, ptr addrspace(2) %in2, align 16
  %add = add <4 x i32> %1, %0
  ret <4 x i32> %add
}

define dso_local spir_kernel void @k1(ptr addrspace(1) nocapture writeonly align 16 %out, ptr addrspace(2) nocapture readonly align 16 %in) !clspv.pod_args_impl !16 {
entry:
  %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x <4 x i32>] } zeroinitializer)
  %1 = getelementptr { [0 x <4 x i32>] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0
  %2 = call ptr addrspace(2) @_Z14clspv.resource.1(i32 0, i32 1, i32 1, i32 1, i32 1, i32 0, { [4096 x <4 x i32>] } zeroinitializer)
  %3 = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) %2, i32 0, i32 0, i32 0
  %4 = load <4 x i32>, ptr addrspace(2) %3, align 16
  %5 = extractelement <4 x i32> %4, i64 0
  %6 = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) %2, i32 0, i32 0, i32 %5
  %7 = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) %2, i32 0, i32 0, i32 1
  %8 = load <4 x i32>, ptr addrspace(2) %7, align 16
  %9 = extractelement <4 x i32> %8, i64 1
  %10 = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) %2, i32 0, i32 0, i32 %9
  %call = tail call spir_func <4 x i32> @bar(ptr addrspace(2) %6, ptr addrspace(2) %10) #2
  store <4 x i32> %call, ptr addrspace(1) %1, align 16
  ret void
}

declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x <4 x i32>] })

declare ptr addrspace(2) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [4096 x <4 x i32>] })

!16 = !{i32 2}

